<meta meta="会员权益配置" args="data"/>
<style>

</style>
<form class="form-horizontal" id="form" s="form,valid">
    <table class="table table-bordered table-condensed table-striped">
        <thead>
        <tr>
            <th>会员级别</th>
            <th>分佣比例</th>
            <th>月工资</th>
            <th>月任务佣金收入</th>
            <th>月任务奖励</th>
            <th class="text-right">操作</th>
        </tr>
        </thead>
        <tbody s="nda,loop" id="profitList" s-data="data.userLevelProfitList">
        <tr s-loop-role="empty">
            <td colspan="6" class="alert alert-warning">暂无数据</td>
        </tr>
        <tr s="row,datac" s-loop-role="row">
            <td>
                <input autocomplete="off" type="text" readonly s-valid-error="require()" class="form-control user-level input-sm" name="userLevel" />
            </td>
            <td>
                <input autocomplete="off" placeholder="commissionRate" type="text" s-valid-error="require(),number(),min(0)" class="form-control commission-rate input-sm" name="commissionRate" />
            </td>
            <td>
                <input autocomplete="off" type="text" s-valid-error="require(),number(),min(0)" class="form-control salary input-sm" name="salary" />
            </td>
            <td>
                <input autocomplete="off" type="text" s-valid-error="require(),number(),min(0)" class="form-control missionCommissionFee input-sm" data-mission="commissionFee" name="monthlyMission.commissionFee" />
            </td>
            <td>
                <input autocomplete="off" type="text" s-valid-error="require(),number(),min(0)" class="form-control missionReward input-sm" data-mission="missionReward" name="monthlyMission.missionReward" />
            </td>
            <td class="text-right">
                <input autocomplete="off" type="button" s-click="del(this)" class="btn btn-sm btn-outline btn-danger" value="删除" />
            </td>
        </tr>
        </tbody>
        <tfoot>
        <tr class="form-inline">
            <td colspan="6">
                <select class="form-control input-sm" s="select"
                        id="userLevel"
                        name="type"
                        s-build="S.get('/api/enum/valuesMap/core.enums.UserLevel')">
                </select>
                <input autocomplete="off" type="button" class="btn btn-sm btn-default" s-click="addNew()" value="新增" />
            </td>
        </tr>
        </tfoot>
    </table>
</form>
<script type="text/javascript">
    S.getContent = function () {
        var deferred = $.Deferred();
        $form.validate().done(function() {
            var obj = {
                userLevelProfitList: []
            }
            var userLevelNodes = $form.node.find(".user-level");
            var commissionRateNodes = $form.node.find(".commission-rate");
            var salaryNodes = $form.node.find(".salary");
            var missionCommissionFeeNodes = $form.node.find(".missionCommissionFee");
            var missionRewardNodes = $form.node.find(".missionReward");
            userLevelNodes.each(function(i) {
                obj.userLevelProfitList.push({
                    userLevel: $(this).val(),
                    commissionRate: commissionRateNodes.get(i).value,
                    salary: salaryNodes.get(i).value,
                    monthlyMission: {
                        commissionFee: missionCommissionFeeNodes.get(i).value,
                        missionReward: missionRewardNodes.get(i).value,
                    }
                })
            })
            deferred.resolve(obj)
        })
        return deferred;
    }
    function addNew() {
        var userLevel = $userLevel.getSelectData();
        $profitList.addRow( {userLevel: userLevel.id}, 'append')
    }
    function del($s) {
        $s.parent().node.remove();
    }
</script>